package com.haiyi.test.demo.controller;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.haiyi.test.demo.ConfigBean;
import com.haiyi.test.demo.DemoApplication;
import com.haiyi.test.demo.Test;
import com.haiyi.test.demo.TestImpl2;
import com.haiyi.test.demo.dao.TestDao;
import com.haiyi.test.demo.jpa.User;
import com.haiyi.test.demo.jpa.UserRepository;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

//@RestController
@Controller
@RequestMapping(produces = "application/json")
@PropertySource("classpath:/abc.yml")
@EnableCaching
public class ControllerImpl {

    @Autowired
    private List<WebMvcConfigurer> config;

    @Autowired
    private TestDao dao;

    @Autowired
    private UserRepository repository;

    @RequestMapping(value = "/hello")
    @ResponseBody
    public String index(ModelMap model) throws IOException {
        System.out.println("test1:"+env.getProperty("ya"));
        byte[] xx = new byte[1024*1024*300];
        return "";
    }

    @Autowired
    private TestImpl2 bean2;

    @RequestMapping(value="/tt",produces = "application/xml")
    @ResponseBody
    public String tt() throws IOException {
        LoggerFactory.getLogger("com.dudu.controller").error("----1log:"+ System.currentTimeMillis());

        return "test";
    }

    @RequestMapping(value="/tt",produces = "application/json")
    @ResponseBody
    public String tt2() throws IOException {
        LoggerFactory.getLogger("com.dudu.controller").warn("----1log:"+ System.currentTimeMillis());

        return "test";
    }

    @RequestMapping(value = {"/test1", "/test2"})
    @ResponseBody
    public String test() throws NoSuchMethodException {
        Method method = this.getClass().getMethod("test");
        RequestMapping a =method.getAnnotation(RequestMapping.class);
        System.out.println(new Timestamp(System.currentTimeMillis()));
        return "112222";
    }
    @RequestMapping(value="jsp/test")
    public String jsp(){
        return "test";
    }
    @RequestMapping("/th")
    @ResponseBody
    public Object idx(String id) {
        Object o = null;
        if("1".equals(id)){
            ModelAndView mv = new ModelAndView("idx");
            mv.addObject("host", "http");
            o = mv;
        }else{
            o = "hello";
        }
        return o;
    }





    @Value("${test}")
    private String test;


    private String aaa;

    @Value("${spring.profiles.active}")
    private String bbb;

    @Autowired
    private Environment env;

    @Value("${demo}")
    private String demo;

    @Qualifier("config")
    @Autowired
    private ConfigBean bean;
}
